home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 42
/
Amiga Format AFCD42 (Issue 126, Aug 1999).iso
/
-serious-
/
comms
/
other
/
amarquee
/
examples
/
geturl.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1999-05-25
|
3KB
|
108 lines
/*************************************************
GetURL.rexx
Author: Håkan Parting (hparting@hem.passagen.se)
An ARexx implementation of GetURL.c. Works pretty much
the same as the C version does! Requires amarquee.library
v49 and rexxamarquee.library V49 or higher.
Usage: rx geturl.rexx [servername] [portNumber]
***************************************************/
parse arg serverName portNum .
if (serverName == '?') then do
say "Usage: rx geturl.rexx [serverName] [portNum]"
say "e.g. rx geturl.rexx 'ACS.hostile.cx' 80"
say " (defaults args are localhost 80)"
exit
end
if (length(serverName) = 0) then serverName = 'localhost'
if (length(portNum) = 0) then portNum = 80
/* We need to trap all the different ways the script could exit,
so that we can be sure any allocated QSessions or QMessages are
freed properly */
signal on error
signal on syntax
signal on halt
signal on break_c
/* Used to track allocated QSession and QMessage */
session = 0
message = 0
terminate = 0
NL = '0a'x
/* Note that we require rexxamarquee.library v49 or higher */
/* Also note that the liboffset must be -30 */
check = addlib('rexxamarquee.library', 0, -30, 49)
/* Here's where we connect to the server... */
say "Connecting to server " || serverName || " on port " || portNum
session = QNewSocketSession(serverName, portNum)
if (session > 0) then do
say "Connection successful."
say "Retrieving index.html at " || serverName
res=QSendRawOp(session,"GET / HTTP/1.0" || NL || NL)
call QGo(session)
MainLoop:
do (terminate~=1)
/* This will block until we get a signal (e.g. CTRL-C) or a QMessage
arrives over our connection. */
message = GetNextQMessage(session, -1, 'SIGBREAKF_CTRL_C')
if (message > 0) then do
if GetQMessageField(message, 'Status') ~= QERROR_NO_ERROR then do
say "Connection closed."
terminate=1
/* We will exit right after this */
end
else
do
/* Print out the web page */
say "**** PACKET START ****"
say GetQMessageField(message, 'Data')
say "**** PACKET END ****"
end
call FreeQMessage(session, message)
message = 0
end /* (message > 0) */
else
do
say "GetNextQMessage returned NULL... probably because we caught a signal."
end
end /* (terminate=0) */
end /* (session > 0) */
else say "Couldn't connect to server, sorry."
/* cleanup sesssion */
if (session > 0) then do
call QFreeSession(session)
end
EXIT
/* Our error handling/cleanup routine starts here */
ERROR:
SYNTAX:
HALT:
BREAK_C:
say "CTRL-C or error detected in line " || sigl
if (message > 0) then do
call FreeQMessage(session, message)
end
if (session > 0) then do
call QFreeSession(session)
end
exit